package com.itheima.功能流.properties;

import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;

public class 登录案例 {
    public static void main(String[] args) throws IOException {
        //通过Properties的load加载正确的用户名密码信息
        // 获取本地储存的用户信息
        Properties prop = new Properties();
        FileReader fr = new FileReader("day13_IO流_功能流\\prop.properties");
        prop.load(fr);
        fr.close();

        //创建键盘录入对象
        Scanner sc = new Scanner(System.in);

        //用户输入
        System.out.println("请输入用户名:");
        String username = sc.nextLine();
        System.out.println("请输入密  码:");
        String passowrd = sc.nextLine();

        //判断
        /*if (prop.containsKey(username)){
            String pwd = prop.getProperty(username);
            if (pwd.equals(passowrd)){
                System.out.println("登录成功");
            }else
                System.out.println("密码错误");

        }else {
            System.out.println("用户名错误");
        }*/
        if (prop.containsKey(username) && prop.getProperty(username).equals(passowrd)){
            System.out.println("登录成功");
        }else
            System.out.println("用户名或密码错误");
    }
}
